package com.nineclock.approve.controller;

import com.nineclock.approve.ApproveDefinitionControllerApi;
import com.nineclock.approve.dto.ApproveDefinitionResultDto;
import com.nineclock.approve.dto.ApproveDefinitionSaveDto;
import com.nineclock.approve.dto.ApproveGroupDefinitionDto;
import com.nineclock.approve.service.ApproveDefinitionService;
import com.nineclock.common.entity.Result;
import com.nineclock.common.utils.UUIDUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/approve")
public class ApproveDefinitionController implements ApproveDefinitionControllerApi {

    @Autowired
    ApproveDefinitionService approveDefinitionService;

    @Override
    @GetMapping("/seq")
    public Result<String> seq() {
        return Result.success(UUIDUtils.getUUID());
    }

    /**
     * 查询流程定义列表
     * @return
     */
    @Override
    @GetMapping("/approveGroupDefinition")
    public Result<List<ApproveGroupDefinitionDto>> queryApproveGroupDefinition() {
        List<ApproveGroupDefinitionDto> definitionDtos = approveDefinitionService.queryApproveGroupDefinition();
        return Result.success(definitionDtos);

    }

    /**
     * 流程定义: 新增/修改
     * @param approveDefinitionSaveDto
     * @return
     */
    @PostMapping("/approveDefinition")
    @Override
    public Result saveApproveDefinition(@RequestBody ApproveDefinitionSaveDto approveDefinitionSaveDto) {
        approveDefinitionService.saveApproveDefinition(approveDefinitionSaveDto);
        return Result.success();
    }

    /**
     * 流程定义: 根据ID查询
     * @param id
     * @return
     */
    @Override
    @GetMapping("/approveDefinition/{id}")
    public Result<ApproveDefinitionResultDto> queryById(@PathVariable("id") String id) {
        ApproveDefinitionResultDto approveDefinitionResultDto = approveDefinitionService.queryById(id);
        return Result.success(approveDefinitionResultDto);
    }

}    